package com.macro.mall.controller.base.klyx;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.controller.base.BaseAdminController;
import com.macro.mall.dto.admin.*;
import com.macro.mall.service.SitQuietlyClockService;
import com.macro.mall.vo.admin.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xq
 * @description 静坐打卡
 * @date 2024/2/20 20:39
 */
@RestController
@Api(tags = "SitQuietlyClockController")
@Tag(name = "SitQuietlyClockController", description = "静坐打卡管理")
@RequestMapping("/sit-quietly-clock")
public class SitQuietlyClockController extends BaseAdminController {
    @Resource
    private SitQuietlyClockService sitQuietlyClockService;


    @ApiOperation(value = "静坐打卡列表查询")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<AdminSitQuietlyClockVO>> listByAdmin(AdminClockQueryDTO req) {
        if (null != req.getStartDate()) {
            req.setStartDateNo(Long.valueOf(DateUtil.format(DateUtil.parse(req.getStartDate(), DatePattern.NORM_DATETIME_PATTERN), DatePattern.PURE_DATE_PATTERN)));
        }
        if (null != req.getEndDate()) {
            req.setEndDateNo(Long.valueOf(DateUtil.format(DateUtil.parse(req.getEndDate(), DatePattern.NORM_DATETIME_PATTERN), DatePattern.PURE_DATE_PATTERN)));
        }
        List<AdminSitQuietlyClockVO> res = sitQuietlyClockService.list(req);
        return CommonResult.success(CommonPage.restPage(res));

    }

    @ApiOperation(value = "旷卡统计列表")
    @GetMapping(value = "/un-clock-list")
    public CommonResult<CommonPage<AdminUnClockListVO>> unClockList(AdminUnClockListDTO req) {
        List<AdminUnClockListVO> res = sitQuietlyClockService.unClockList(req);
        return CommonResult.success(CommonPage.restPage(res));

    }

    @ApiOperation(value = "待打卡用户列表")
    @GetMapping(value = "/pre-clock-list")
    public CommonResult preClockList(AdminPreClockDTO req) {
        List<String> res = sitQuietlyClockService.preClockList(req);
        return CommonResult.success(res);

    }

    @ApiOperation(value = "待打卡统计数据")
    @GetMapping(value = "/pre-clock-data")
    public CommonResult<AdminPreClockDataVO> preClockData(AdminPreClockDTO req) {
        AdminPreClockDataVO res = sitQuietlyClockService.preClockDataVO(req);
        return CommonResult.success(res);

    }

    @ApiOperation(value = "新增静坐打卡")
    @PostMapping(value = "/clock")
    public CommonResult addClock(@Validated @RequestBody AdminClockAddDTO req) {
        sitQuietlyClockService.addClock(req);
        return CommonResult.success();

    }

    @ApiOperation(value = "删除静坐打卡")
    @DeleteMapping(value = "/clock/{id}")
    public CommonResult deleteClock(@PathVariable Long id) {
        sitQuietlyClockService.deleteClock(id);
        return CommonResult.success();

    }

    @ApiOperation(value = "修改静坐打卡")
    @PutMapping(value = "/clock")
    public CommonResult updateClock(@Validated @RequestBody AdminClockUpdateDTO req) {
        sitQuietlyClockService.updateClock(req);
        return CommonResult.success();

    }

    @ApiOperation(value = "获取用户名称")
    @GetMapping(value = "/username/{type}")
    public CommonResult<List<AdminUserNameVO>> getUserNameList(@PathVariable Integer type) {
        List<AdminUserNameVO> adminUserNameVOS = sitQuietlyClockService.listUserNames(type);
        return CommonResult.success(adminUserNameVOS);
    }

    @ApiOperation(value = "获取旷卡用户名称")
    @GetMapping(value = "/listUnClock/{type}")
    public CommonResult<List<UnClockUserVO>> listUnClock(@PathVariable Integer type) {
        List<UnClockUserVO> res = sitQuietlyClockService.listUnClock(type);
        return CommonResult.success(res);

    }


}
